package com.mystyle.le.qjnewsproject.utils;

import com.mystyle.le.qjnewsproject.beans.TopAd;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by le on 2016/10/8.
 */
public class ParseJson {
    public static List<TopAd> parseJson(String path){
        List<TopAd> list = new ArrayList<>();
        try {
            JSONArray jsonObject = new JSONArray(path);
            if (jsonObject!=null){
                for (int i =0;i<jsonObject.length();i++){
                    JSONObject jsonObject1 = jsonObject.getJSONObject(i);
                    String title = jsonObject1.getString("title");
                    String icon = jsonObject1.getString("icon");
                    list.add(new TopAd(title,icon));
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }

        return list;
    }
}
